﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Wfxin.Models
{
    /// <summary>
    /// 结果实体
    /// </summary>
    public class ResultInfo
    {

        /// <summary>
        /// 返回的标识码
        /// </summary>
        public int Status { get; set; }

        private string message = string.Empty;
        /// <summary>
        /// 返回的消息
        /// </summary>
        public string Message
        {
            get { return message.Replace("\\r\\n", Environment.NewLine); }
            set { message = value; }
        }

        /// <summary>
        /// 成功
        /// </summary>
        public bool Success
        {
            get { return Status == 0; }
        }

        /// <summary>
        /// 
        /// </summary>
        public ResultInfo()
        {
            Status = 0;
            Message = "成功";
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="flag"></param>
        /// <param name="msg"></param>
        public ResultInfo(object flag, object msg)
        {
            int.TryParse(flag.ToString(), out int f);
            Status = f;
            Message = msg.ToString();
        }

        public override string ToString()
        {
            return string.Format("返回状态：{0}, 返回信息：{1}", Status, Message);
        }

    }

    /// <summary>
    /// 结果实体
    /// </summary>
    public class ResultInfo<T> : ResultInfo
    {
        /// <summary>
        /// 
        /// </summary>
        public ResultInfo() : base() { }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="flag"></param>
        /// <param name="msg"></param>
        public ResultInfo(object flag, object msg) : base(flag, msg) { }

        /// <summary>
        /// 返回的数据
        /// </summary>
        public T Result { get; set; }
    }

    /// <summary>
    /// 结果实体
    /// </summary>
    public class ListResultInfo<Tt> : ResultInfo<Tt>
    {
        /// <summary>
        /// 页面唯一标识
        /// </summary>
        public string UniqueId { get; set; } = Guid.NewGuid().ToString("N").ToUpper();

        /// <summary>
        /// 
        /// </summary>
        public ListResultInfo() : base()
        {
            TotalItem = 0L;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="flag"></param>
        /// <param name="msg"></param>
        public ListResultInfo(object flag, object msg) : base(flag, msg) { }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="flag"></param>
        /// <param name="msg"></param>
        /// <param name="totalCount"></param>
        public ListResultInfo(object flag, object msg, object totalCount) : base(flag, msg)
        {
            long.TryParse(totalCount.ToString(), out long t);
            TotalItem = t;
        }

        /// <summary>
        /// 总项数
        /// </summary>
        public long TotalItem { get; set; }

        /// <summary>
        /// 总记录数，分页时使用
        /// </summary>
        public long GetRotalItem()
        {
            return TotalItem;
        }

        /// <summary>
        /// 总记录数，分页时使用
        /// </summary>
        public void SetTotalItem(long value)
        {
            TotalItem = value;
        }
    }
}
